FROM ubuntu:14.04
MAINTAINER caoyue <i@caoyue.me>

# env config
ENV OTP_VERSION 17.5

# mirror
RUN echo "deb http://mirrors.ustc.edu.cn/ubuntu/ trusty main restricted universe multiverse" > /etc/apt/sources.list \
    && echo "deb http://mirrors.ustc.edu.cn/ubuntu/ trusty-security main restricted universe multiverse" >> /etc/apt/sources.list \
    && echo "deb http://mirrors.ustc.edu.cn/ubuntu/ trusty-updates main restricted universe multiverse" >> /etc/apt/sources.list \
    && echo "deb http://mirrors.ustc.edu.cn/ubuntu/ trusty-proposed main restricted universe multiverse" >> /etc/apt/sources.list \
    && echo "deb http://mirrors.ustc.edu.cn/ubuntu/ trusty-backports main restricted universe multiverse" >> /etc/apt/sources.list \
    && echo "deb-src http://mirrors.ustc.edu.cn/ubuntu/ trusty main restricted universe multiverse" >> /etc/apt/sources.list \
    && echo "deb-src http://mirrors.ustc.edu.cn/ubuntu/ trusty-security main restricted universe multiverse" >> /etc/apt/sources.list \
    && echo "deb-src http://mirrors.ustc.edu.cn/ubuntu/ trusty-updates main restricted universe multiverse" >> /etc/apt/sources.list \
    && echo "deb-src http://mirrors.ustc.edu.cn/ubuntu/ trusty-proposed main restricted universe multiverse" >> /etc/apt/sources.list \
    && echo "deb-src http://mirrors.ustc.edu.cn/ubuntu/ trusty-backports main restricted universe multiverse" >> /etc/apt/sources.list

# install packages
RUN apt-get update -y && apt-get install -y wget \
                                            git \
                                            make \
                                            build-essential \
                                            libncurses5-dev \
                                            openssl \
                                            libssl-dev \
                                            fop \
                                            xsltproc \
                                            unixodbc-dev

# install erlang
# erlang-solution so slow :(
# RUN wget https://packages.erlang-solutions.com/erlang-solutions_1.0_all.deb
# RUN dpkg -i erlang-solutions_1.0_all.deb
# RUN apt-get update
# RUN apt-get install -y erlang

# ADD http://erlang.org/download/otp_src_${OTP_VERSION}.tar.gz /usr/src/
COPY ./otp_src_${OTP_VERSION}.tar.gz /usr/src/
RUN cd /usr/src \
    && tar xf otp_src_${OTP_VERSION}.tar.gz \
    && cd otp_src_${OTP_VERSION} \
    && ./configure \
    && make \
    && make install \
    && cd / \
    && rm -rf /usr/src/otp_src_${OTP_VERSION}

# rebar
RUN cd /usr/src \
    && git clone https://github.com/rebar/rebar \
    && cd rebar \
    && ./bootstrap \
    && cp rebar /usr/bin/rebar \
    && cd / \
    && rm -rf /usr/src/rebar


# CMD ["erl"]

